// /pages/shebao/shebao.js
var choseCity = require("../../../../utils/formula");
const utils = require("../../.././../utils/util");
let toggleCollection = true;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    registerArray: ["深户", "非深户"],
    levelArray: ["一档", "二档", "三档"],
    regindex: 0,
    levindex: 0,
    switchChecked: false,
    disabled: false,
    pickSel: false,
    showTips: false,
    scroll: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // utils.colleation(this, "社保缴费计算");
    toggleCollection = true;
    // 默认户口值
    this.data.registerArray.map((item, index) => {
      if (index == this.data.regindex) {
        this.setData({
          register: item
        })

        if (this.data.register == "深户") {
          this.setData({
            pickSel: true
          })
        } else {
          this.setData({
            pickSel: false
          })
        }
      }
    })

    // 默认医保档次
    this.data.levelArray.map((item, index) => {
      if (index == this.data.levindex) {
        this.setData({
          level: item
        })
      }
    })
  },

  // 户口选择
  bindRegChange: function (e) {
    this.setData({
      regindex: e.detail.value
    })

    this.data.registerArray.map((item, index) => {
      if (index == this.data.regindex) {
        this.setData({
          register: item
        })

        if (this.data.register == "深户") {
          this.setData({
            pickSel: true,
            levindex: 0
          })
        } else {
          this.setData({
            pickSel: false
          })
        }
      }
    })
  },

  // 医保档次
  bindLevChange: function (e) {
    this.setData({
      levindex: e.detail.value
    })

    this.data.levelArray.map((item, index) => {
      if (index == this.data.levindex) {
        this.setData({
          level: item
        })
      }
    })
  },

  // 最低基数
  inputBase: function (e) {
    let numBase = e.detail.value;
    this.setData({
      numBase,
    })
  },
  // 最低基数按钮
  switchChange: function (e) {
    let baseflag = e.detail.value;
    if (baseflag) {
      this.setData({
        numBase: 2200,
        disabled: true,
      })
    } else {
      this.setData({
        disabled: false,
      })
    }
  },

  // 开始计算
  computed: function (e) {
    if (this.data.numBase) {
      let computeData = {
        register: this.data.register,
        level: this.data.level,
        basePayment: this.data.numBase,
      }

      wx.navigateTo({
        url: '../result/result?computeData=' + JSON.stringify(computeData),
      })
    } else {
      wx.showToast({
        title: '请补全信息',
        icon: 'none',
      });
    }

  },
  showSing() {
    this.setData({
      showTips: true,
    });
    setTimeout(() => {
      this.setData({
        showTips: false,
      })
    }, 1500);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return { imageUrl: "http://imgbdb3.bendibao.com/xcxbdb/file/20212/9/20210209161843_68677.jpg" }
  },
  onPageScroll() {
    if (toggleCollection) {
      this.setData({
        scroll: true,
      });
      toggleCollection = false;
    }

  },
  closeCollection() {
    toggleCollection = false;
  },
  openCollection() {
    toggleCollection = true;
  }
})